<?php


// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view' );
class ShopViewUpdate_settings extends JView
{
	function display($tpl = null)
	{
		JToolBarHelper::title(JText::_( 'Настройки обновления прайса' ), 'generic.png');
		JToolBarHelper::save('saveUpdateConfig');
		JToolBarHelper::cancel('cancelUpdateConfig');
		
		$mainframe = &JFactory::getApplication();
		$db = & JFactory::getDBO();
		$csv_path = 'http://eroticfantasy.ru/EF_PerechenSkollekciyami.csv';
                //printu($csv_path,'get file');
                //$root_dir = str_replace($_SERVER['PHP_SELF'], '', $_SERVER['SCRIPT_FILENAME']);
                //$path = $root_dir.'/tmp';
                //$f_name = $path.'/import.tmp';
                //$fconv_name = $path.'/_import.tmp';
                //printu(file_exists($path.'/import.tmp'),'file '.$f_name);
//$aFile = file($f_name);
//printu(count($aFile),'aFile');
//$csv = iconv('windows-1251','utf-8',  implode("\n", $aFile));
//printu(strlen($csv),'strlen file');
//$r = file_put_contents($fconv_name, $csv);
//printu($r,'res put');

                $f_name = 'import.tmp';
		$csv = iconv('windows-1251','utf-8',file_get_contents($csv_path));
                //printu(strlen($csv),'strlen file');
		file_put_contents($f_name, $csv);
                //printu('save file');

        $handle = fopen($f_name, "r");
        //printu($handle,'handle');
        $access_cat = array(
            '1'=>array('05933','00804','05913','01036','00376','00841','00653','01034','00412','00382',
                '00467','01035','00385','02136','00389','00504','00378','00506','00406','01438','02712',
                '00881'),
            '2'=>array('00965'),
        );
		while (($data = fgets($handle)) !== FALSE) {
                    //printu($data,'line text');
                    $data = explode(';',$data);
                        // не читаем товары
                        if ($data[0]==0) continue;
                        //printu($data,'line');
                        // выбираем нужные категории
			if(($data[0]==1 && in_array($data[2],$access_cat['2'])) || in_array($data[1],$access_cat['1']))
                            $rows[] = $data;

        } 
	//	echo '<pre>';
		$this->assignRef('rows',$rows);
	//	var_dump($rows);
        fclose($handle); 
        //unlink('import.tmp');
		
		
		$query = "SELECT * FROM #__shop_category_comparison";
		$db->setQuery($query);
		$comparison = $db->loadRowList();
		
		$this->assignRef('comparison',$comparison);
		
		$query = "SELECT id,name FROM #__shop_categories ORDER BY ordering ASC";
		$db->setQuery($query);
		$categories = $db->loadAssocList();
		
		$this->assignRef('categories',$categories);
		parent::display($tpl);
	}
	
	function _translate($title)
	{
		$tbl= array(
			'а'=>'a', 'б'=>'b', 'в'=>'v', 'г'=>'g', 'д'=>'d', 'е'=>'e', 'ж'=>'g', 'з'=>'z',
			'и'=>'i', 'й'=>'y', 'к'=>'k', 'л'=>'l', 'м'=>'m', 'н'=>'n', 'о'=>'o', 'п'=>'p',
			'р'=>'r', 'с'=>'s', 'т'=>'t', 'у'=>'u', 'ф'=>'f', 'ы'=>'i', 'э'=>'e', 'А'=>'A',
			'Б'=>'B', 'В'=>'V', 'Г'=>'G', 'Д'=>'D', 'Е'=>'E', 'Ж'=>'G', 'З'=>'Z', 'И'=>'I',
			'Й'=>'Y', 'К'=>'K', 'Л'=>'L', 'М'=>'M', 'Н'=>'N', 'О'=>'O', 'П'=>'P', 'Р'=>'R',
			'С'=>'S', 'Т'=>'T', 'У'=>'U', 'Ф'=>'F', 'Ы'=>'I', 'Э'=>'E', 'ё'=>"yo", 'х'=>"h",
			'ц'=>"ts", 'ч'=>"ch", 'ш'=>"sh", 'щ'=>"shch", 'ъ'=>"", 'ь'=>"", 'ю'=>"yu", 'я'=>"ya",
			'Ё'=>"YO", 'Х'=>"H", 'Ц'=>"TS", 'Ч'=>"CH", 'Ш'=>"SH", 'Щ'=>"SHCH", 'Ъ'=>"", 'Ь'=>"",
			'Ю'=>"YU", 'Я'=>"YA", ' '=>"-", '('=>'', ')'=>'', ','=>'', '.'=>''
			);

		$translate = mb_strtolower(strtr($title, $tbl));
		return $translate;
	}

	
}

?>